<include file="Public:header_content" />
<link href="/Public/plugin/gb312/css/plugins/datapicker/datepicker3.css" rel="stylesheet" type="text/css"/>
<link href="/Public/plugin/gb312/css/plugins/summernote/summernote.css"  rel="stylesheet">
<link href="/Public/plugin/gb312/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">

<div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="ibox-tools">
                            <a class="back-link" href="javascript:history.go(-1);">
                                <i class="fa fa-chevron-left"></i>
                            </a>
                        </div>
                        <form method="get" id="add-book-form" class="form-horizontal">
                            <div class="form-group search_val">
                                <label class="col-sm-2 control-label">书本名称</label>
                                <div class="col-sm-4">
                                    <div class="input-group">
                                        <input type="text" name="book_name" value="<{$book_name}>" class="form-control"> 
                                        <span class="input-group-btn"> 
                                            <button id="search_name" type="button" class="btn btn-primary">搜索</button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">作者</label>
                                <div class="col-sm-2">
                                    <div class="input-group">
                                        <input type="text" name="author_name" value="" class="form-control"> 
                                            <span class="input-group-btn"> 
                                                <button id="author_name" type="button" class="btn btn-primary">搜索</button>
                                            </span>
                                    </div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group article_name">
                                <label class="col-sm-2 control-label">分类</label>
                                <div class="col-sm-2">
                                    <select class="form-control m-b" name="cate_id">
                                        <volist name="cates" id="cate">
                                            <option value="<{$cate.cate_id}>"><{$cate.cate_name}>小说</option>
                                        </volist>
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">更新时间</label>
                                <div class="col-sm-2 input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" name="create_time" class="form-control" value="2017-3-11" readonly />
                                </div>
                            </div>
                           
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" id="submit" type="submit">保存</button>
                                    <button class="btn btn-white" type="submit">取消</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>


<include file="Public:footer_content" />
<script src="/Public/plugin/gb312/js/plugins/datapicker/bootstrap-datepicker.js" type="text/javascript"></script>
<script src="/Public/plugin/gb312/js/plugins/summernote/summernote.min.js" ></script>
<script src="/Public/plugin/gb312/js/plugins/summernote/summernote-zh-CN.js" ></script>

<script type="text/javascript">
    
    
    $(function(){
        $(".click2edit").summernote({
            //height: 300, 
            minHeight: 300,
            callbacks: {  
                onImageUpload: function(files){ //the onImageUpload API  
                    img = sendFile(files[0]);  
                }
            },
            lang:"zh-CN",
            focus:true
        });
        
        $(".input-group.date").datepicker({
            todayBtn:"linked",
            keyboardNavigation:!1,
            forceParse:!1,
            calendarWeeks:!0,
            autoclose:!0
        });
        
        var content = $(".click2edit").code();
        
      
                    var e="<i class='fa fa-times-circle'></i> ";
                    $("#add-book-form").validate({
			rules:{
				book_name:{
                                    required:!0,
                                    remote: {
                                        url: "<{:U('Book/checkBookName')}>",     //后台处理程序
                                        type: "post",               //数据发送方式
                                        dataType: "json",           //接受数据格式   
                                        data: {                     //要传递的数据
                                            mobile:function(){
                                                return $('input[name="book_name"]').val(); 
                                            }
                                        }
                                    }
                                },
                                article_name:{
                                    required:!0
                                }
			},
			messages:{
				book_name:{
                                    required:e+"请输入书本名称",
                                    remote:e+"该书本名称不存在"
                                },
                                article_name:{
                                    required:e+"请输入章节名称",
                                    remote:e+"该书章节名称已存在"
                                }
			}
		});

        
    });
    
    function sendFile(file){
        data = new FormData();  
        data.append("file", file);  
        console.log(data);  
        $.ajax({  
            data: data,  
            type: "POST",  
            url: "{:U('Test/upload')}", 
            success: function(url) {
                  $(".click2edit").summernote('insertImage', url, 'image name'); // the insertImage API  
            }
        });  
    }  
    
    function articleNameCheck(){
        var book_name = $('input[name="book_name"]').val();
        article_name = $('input[name="article_name"]').val();
        $.ajax({  
            data: 'book_name='+book_name+'&article_name='+article_name,
            type: "POST",
            url: "<{:U('Book/checkArtcileRepeat')}>",
            success: function(msg){
                if(msg == 'success'){
                    $('.form-group.article_name').removeClass('has-error');
                    $('.form-group.article_name').addClass('has-success');
                    flag = true;
                }else{
                    $('.form-group.article_name').addClass('has-error');
                    flag = false;
                }
            }
        });
    }
    
    
    function bookNameCheck(){
        var search_val = $('input[name="book_name"]').val(); 
        $.ajax({  
            data: 'book_name='+search_val,
            type: "POST",
            url: "<{:U('Book/checkBookName')}>",
            success: function(msg){
                if(msg == 'success'){
                    $('.form-group.search_val').removeClass('has-error');
                    $('.form-group.search_val').addClass('has-success');
                    flag = true;
                }else{
                    $('.form-group.search_val').addClass('has-error');
                    flag = false;
                }
            }
        });
        
    }
    

  
    
    
    
    
</script>